package org.nfyszny.zzzs.modules.controller;

import java.util.Arrays;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.aspect.annotation.AutoDict;
import org.jeecg.common.system.query.QueryGenerator;
import org.nfyszny.zzzs.modules.entity.ZzzsRecordOfSupplyAbility;
import org.nfyszny.zzzs.modules.service.IZzzsRecordOfSupplyAbilityService;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.extern.slf4j.Slf4j;

import org.jeecg.common.system.base.controller.JeecgController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.jeecg.common.aspect.annotation.AutoLog;

 /**
 * @Description: 供货能力备案
 * @Author: jeecg-boot
 * @Date:   2022-11-11
 * @Version: V1.0
 */
@Api(tags="供货能力备案")
@RestController
@RequestMapping("/modules/zzzsRecordOfSupplyAbility")
@Slf4j
public class ZzzsRecordOfSupplyAbilityController extends JeecgController<ZzzsRecordOfSupplyAbility, IZzzsRecordOfSupplyAbilityService> {
	@Autowired
	private IZzzsRecordOfSupplyAbilityService zzzsRecordOfSupplyAbilityService;

	 /**
	  * 根据id获取状态
	  * @param productId
	  * @return
	  */
	 @ApiOperation(value="供货能力备案-分页列表查询", notes="供货能力备案-分页列表查询")
	 @GetMapping(value = "/getRecordStatus/{productId}")
	 public Result getRecordStatusAbility(@PathVariable("productId")String productId) {
		 Map<String,Object> map=zzzsRecordOfSupplyAbilityService.getStateAbility(productId);
		 return Result.TOK(map);
	 }
	 /**
	  * 分页列表查询
	  *
	  * @param
	  * @param pageNo
	  * @param pageSize
	  * @param req
	  * @return
	  */
	 //@AutoLog(value = "生产能力备案-分页列表查询")
	 @ApiOperation(value="供货能力备案-根据产品id分页列表查询", notes="供货能力备案-根据产品id分页列表查询")
	 @GetMapping(value = "/getListByProductId")
	 @AutoDict
	 public Result<IPage<ZzzsRecordOfSupplyAbility>> getListByProductId(ZzzsRecordOfSupplyAbility zzzsRecordOfSupplyAbility,
																				@RequestParam(name="pageNo", defaultValue="1") Integer pageNo,
																				@RequestParam(name="pageSize", defaultValue="10") Integer pageSize,
																				HttpServletRequest req) {
		 QueryWrapper<ZzzsRecordOfSupplyAbility> queryWrapper = QueryGenerator.initQueryWrapper(zzzsRecordOfSupplyAbility, req.getParameterMap());
		 Page<ZzzsRecordOfSupplyAbility> page = new Page<ZzzsRecordOfSupplyAbility>(pageNo, pageSize);
		 IPage<ZzzsRecordOfSupplyAbility> pageList =zzzsRecordOfSupplyAbilityService.getListByProductId(queryWrapper,page);

		 return Result.TOK(pageList);
	 }
	/**
	 * 分页列表查询
	 *
	 * @param zzzsRecordOfSupplyAbility
	 * @param pageNo
	 * @param pageSize
	 * @param req
	 * @return
	 */
	//@AutoLog(value = "供货能力备案-分页列表查询")
	@ApiOperation(value="供货能力备案-分页列表查询", notes="供货能力备案-分页列表查询")
	@GetMapping(value = "/list")
	public Result<IPage<ZzzsRecordOfSupplyAbility>> queryPageList(ZzzsRecordOfSupplyAbility zzzsRecordOfSupplyAbility,
								   @RequestParam(name="pageNo", defaultValue="1") Integer pageNo,
								   @RequestParam(name="pageSize", defaultValue="10") Integer pageSize,
								   HttpServletRequest req) {
		QueryWrapper<ZzzsRecordOfSupplyAbility> queryWrapper = QueryGenerator.initQueryWrapper(zzzsRecordOfSupplyAbility, req.getParameterMap());
		Page<ZzzsRecordOfSupplyAbility> page = new Page<ZzzsRecordOfSupplyAbility>(pageNo, pageSize);
		IPage<ZzzsRecordOfSupplyAbility> pageList = zzzsRecordOfSupplyAbilityService.page(page, queryWrapper);
		return Result.TOK(pageList);
	}

	
	/**
	 *   新增供货能力备案
	 *
	 * @param zzzsRecordOfSupplyAbility
	 * @return
	 */
	@AutoLog(value = "供货能力备案-新增供货能力备案")
	@ApiOperation(value="供货能力备案-新增供货能力备案", notes="供货能力备案-新增供货能力备案")
	//@RequiresPermissions("org.nfyszny.zzzs:zzzs_record_of_supply_ability:add")
	@PostMapping(value = "/add")
	public Result<String> add(@RequestBody ZzzsRecordOfSupplyAbility zzzsRecordOfSupplyAbility) {
		zzzsRecordOfSupplyAbilityService.saveRecordOfSupplyAbility(zzzsRecordOfSupplyAbility);
		return Result.TOK("添加成功！");
	}
	 /**
	  *   提交供货能力备案
	  *
	  * @param zzzsRecordOfSupplyAbility
	  * @return
	  */
	 @AutoLog(value = "供货能力备案-提交供货能力备案")
	 @ApiOperation(value="供货能力备案-提交供货能力备案", notes="供货能力备案-提交供货能力备案")
	 //@RequiresPermissions("org.nfyszny.zzzs:zzzs_record_of_supply_ability:add")
	 @PostMapping(value = "/submitRecord")
	 public Result<String> submitRecord(@RequestBody ZzzsRecordOfSupplyAbility zzzsRecordOfSupplyAbility) {
		 zzzsRecordOfSupplyAbilityService.submitRecord(zzzsRecordOfSupplyAbility);
		 return Result.TOK("添加成功！");
	 }
	
	/**
	 *  编辑
	 *
	 * @param zzzsRecordOfSupplyAbility
	 * @return
	 */
	@AutoLog(value = "供货能力备案-编辑")
	@ApiOperation(value="供货能力备案-编辑", notes="供货能力备案-编辑")
	//@RequiresPermissions("org.nfyszny.zzzs:zzzs_record_of_supply_ability:edit")
	@RequestMapping(value = "/edit", method = {RequestMethod.PUT,RequestMethod.POST})
	public Result<String> edit(@RequestBody ZzzsRecordOfSupplyAbility zzzsRecordOfSupplyAbility) {
		zzzsRecordOfSupplyAbilityService.updateById(zzzsRecordOfSupplyAbility);
		return Result.TOK("编辑成功!");
	}
	
	/**
	 *   通过id删除
	 *
	 * @param id
	 * @return
	 */
	@AutoLog(value = "供货能力备案-通过id删除")
	@ApiOperation(value="供货能力备案-通过id删除", notes="供货能力备案-通过id删除")
	//@RequiresPermissions("org.nfyszny.zzzs:zzzs_record_of_supply_ability:delete")
	@DeleteMapping(value = "/delete")
	public Result<String> delete(@RequestParam(name="id",required=true) String id) {
		zzzsRecordOfSupplyAbilityService.removeById(id);
		return Result.TOK("删除成功!");
	}

	 /**
	  * 供货能力备案变更
	  * @param zzzsRecordOfSupplyAbility
	  * @return
	  */
	 @AutoLog(value = "供货能力备案-修改备案")
	 @ApiOperation(value="供货能力备案-修改备案", notes="供货能力备案-修改备案")
	 //@RequiresPermissions("org.nfyszny.zzzs:zzzs_record_of_supply_ability:delete")
	 @PutMapping(value = "/change")
	 public Result<String> change(@RequestBody ZzzsRecordOfSupplyAbility zzzsRecordOfSupplyAbility) {
		 zzzsRecordOfSupplyAbilityService.change(zzzsRecordOfSupplyAbility);
		 return Result.TOK("删除成功!");
	 }

	 /**
	  * 年审备案
	  * @param zzzsRecordOfSupplyAbility
	  * @return
	  */
	 @AutoLog(value = "供货能力备案-修改备案")
	 @ApiOperation(value="供货能力备案-修改备案", notes="供货能力备案-修改备案")
	 //@RequiresPermissions("org.nfyszny.zzzs:zzzs_record_of_supply_ability:delete")
	 @PutMapping(value = "/review")
	 public Result<String> review(@RequestBody ZzzsRecordOfSupplyAbility zzzsRecordOfSupplyAbility) {
		 zzzsRecordOfSupplyAbilityService.review(zzzsRecordOfSupplyAbility);
		 return Result.TOK("删除成功!");
	 }

	 /**
	 *  批量删除
	 *
	 * @param ids
	 * @return
	 */
	@AutoLog(value = "供货能力备案-批量删除")
	@ApiOperation(value="供货能力备案-批量删除", notes="供货能力备案-批量删除")
	//@RequiresPermissions("org.nfyszny.zzzs:zzzs_record_of_supply_ability:deleteBatch")
	@DeleteMapping(value = "/deleteBatch")
	public Result<String> deleteBatch(@RequestParam(name="ids",required=true) String ids) {
		this.zzzsRecordOfSupplyAbilityService.removeByIds(Arrays.asList(ids.split(",")));
		return Result.TOK("批量删除成功!");
	}
	 /**
	  * getHaveInfoById
	  */
	 @ApiOperation(value = "生产能力备案-查询已备案完成的备案信息", notes = "生产能力备案-查询已备案完成的备案信息")
	 @GetMapping(value = "/getHaveInfoById")
	 public Result<ZzzsRecordOfSupplyAbility> getHaveInfoById(@RequestParam(name = "id", required = true) String id) {
		 ZzzsRecordOfSupplyAbility zzzsRecordOfSupplyAbility = zzzsRecordOfSupplyAbilityService.getHaveInfoById(id);
		 if (zzzsRecordOfSupplyAbility == null) {
			 return Result.error("未找到对应数据");
		 }
		 return Result.TOK(zzzsRecordOfSupplyAbility);
	 }
	/**
	 * 通过id查询
	 *
	 * @param id
	 * @return
	 */
	//@AutoLog(value = "供货能力备案-通过id查询")
	@ApiOperation(value="供货能力备案-通过id查询", notes="供货能力备案-通过id查询")
	@GetMapping(value = "/queryById")
	public Result<ZzzsRecordOfSupplyAbility> queryById(@RequestParam(name="id",required=true) String id) {
		ZzzsRecordOfSupplyAbility zzzsRecordOfSupplyAbility = zzzsRecordOfSupplyAbilityService.getById(id);
		if(zzzsRecordOfSupplyAbility==null) {
			return Result.error("未找到对应数据");
		}
		return Result.TOK(zzzsRecordOfSupplyAbility);
	}

    /**
    * 导出excel
    *
    * @param request
    * @param zzzsRecordOfSupplyAbility
    */
    //@RequiresPermissions("org.nfyszny.zzzs:zzzs_record_of_supply_ability:exportXls")
    @RequestMapping(value = "/exportXls")
    public ModelAndView exportXls(HttpServletRequest request, ZzzsRecordOfSupplyAbility zzzsRecordOfSupplyAbility) {
        return super.exportXls(request, zzzsRecordOfSupplyAbility, ZzzsRecordOfSupplyAbility.class, "供货能力备案");
    }

    /**
      * 通过excel导入数据
    *
    * @param request
    * @param response
    * @return
    */
    //@RequiresPermissions("zzzs_record_of_supply_ability:importExcel")
    @RequestMapping(value = "/importExcel", method = RequestMethod.POST)
    public Result<?> importExcel(HttpServletRequest request, HttpServletResponse response) {
        return super.importExcel(request, response, ZzzsRecordOfSupplyAbility.class);
    }

}
